<template>
    <div>
        <el-card class="box-card" shadow="hover">
            <div slot="header" class="clearfix">
                <span>公开招标中标审核</span>
                <div style="float: right;">
                    <el-button size="small" @click="onClose">取 消</el-button>
                    <el-button size="small" type="danger">驳回</el-button>
                    <el-button size="small" type="primary" @click="onFormSubmit">保存</el-button>
                </div>
            </div>
            <table class="custom-table" style="margin-bottom:10px;">
                <tr><td class="tr-title">项目名称</td><td>{{row.name}}</td></tr>
            </table>
            <el-table :data="tableData" class="radioClass" style="width: 100%;" stripe>
                <el-table-column prop="supplierName" label="供应商名称"></el-table-column>
                <el-table-column prop="isBid" label="是否中标">
                    <template slot-scope="scope">
                        <el-radio :label="scope.$index" v-model="radioId" @change.native="getCurrentRow(scope.row)">&nbsp;</el-radio>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>

        <el-card class="box-card" shadow="hover">
            <div slot="header" class="clearfix">
                <span>其他</span>
            </div>
            <table class="custom-table" style="margin-top:10px;">
                <tr><td class="tr-title wally-label">开标时间</td>
                    <td>
                        {{row.openTime | formatTime}}
                    </td>
                </tr>
                <tr><td class="tr-title">评分方法</td>
                    <td>{{row.remarks}}</td>
                </tr>
                <tr><td class="tr-title wally-label">中标价</td>
                    <td>
                       <el-input v-model="winningMoney"></el-input>
                    </td>
                </tr>
                <tr><td class="tr-title wally-label">中标原因说明</td>
                    <td><el-input type="textarea" v-model="explain"></el-input></td>
                </tr>
            </table>
        </el-card>

       

    </div>
</template>

<script>
    import moment from 'moment'
    import { 
        bidPurchaseInquiryInvitationSetWinSupplier,
        bidPurchaseInquiryInvitationEnrollDetails,
        bidPurchaseOvert
    } from "@/api/purchase_api"
    export default {
        props: ['row'],
        data() {
            return {
                explain:"",//评分方法
                tableData:[],
                radioId:false,//选中供应商id
                winningSupplierId:'',//传后端供应商id
                winningMoney:''//中标价
            };
        },
        filters: {
            formatData(value) {
                if (!value) {
                    return ''
                }
                return moment(value).format("YYYY-MM-DD")
            },
            formatTime(value) {
                if (!value) {
                    return ''
                }
                return moment(value).format("YYYY-MM-DD HH:mm:ss")
            }
        },
        mounted(){
            this.getDetails();//获取报名详情
        },
        methods: { 
            async getDetails(){
                const {code,data} = await bidPurchaseInquiryInvitationEnrollDetails(this.row.id);
                if(code === 200){
                    this.tableData = data;
                }
            },
            getCurrentRow(row){
                this.winningSupplierId = row.supplierId;
            },
            //提交中标审核
            onFormSubmit(){
                if(!this.winningSupplierId){
                    return this.$message.error('请勾选供应商中标');
                }
                if(!this.winningMoney){
                    return this.$message.error('请填写中标价');
                }
                if(!this.explain){
                    return this.$message.error('请填写中标原因');
                }
                this.$confirm("确认提交", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
                }).then(async () => {
                    let params = {};
                    params.explain = this.explain;
                    params.id = this.row.id;
                    params.winningSupplierId = this.winningSupplierId;
                    params.winningMoney = (this.winningMoney*100);
                    let { code } = await bidPurchaseInquiryInvitationSetWinSupplier(params);
                    if(code === 200){
                        this.$message.success("审核成功");
                        this.bidOvert();//评审通过后 执行一下公示接口 让数据流转到合同里面，
                        this.onClose();
                    }
                }).catch(() => {});
            },
            async bidOvert(){
                //1 公示，0 不公示 2撤回   默认不公示
                await bidPurchaseOvert(this.row.id,0);
            },
            //关闭报价
            onClose(){
                this.winningSupplierId = '';
                this.winningMoney = '';
                this.explain = '';
                this.radioId = '';
                this.$emit('on-cancel-click','bidIsReview');
            }
        }
    };
    </script>
    
    <style>
        .wally-label:before {
            content: "*";
            color: #f56c6c;
            margin-right: 4px;
        }
    </style>